
#include "yudie.h"
#include "gpio_buzzer.h"
#include "buzzer_driver.h"
#include "wkup_driver.h"

const uint16_t LOW1 = 262;
const uint16_t  LOW2 = 294;
const uint16_t  LOW3 = 330;
const uint16_t LOW4 = 349;
const uint16_t LOW5 = 392;
const uint16_t LOW6 = 440;
const uint16_t LOW7 = 494;

const uint16_t Middle1 = 523;
const uint16_t Middle2 = 587;;
const uint16_t Middle3 = 659;
const uint16_t Middle4 = 698;
const uint16_t Middle5 = 784;
const uint16_t Middle6 = 880;
const uint16_t Middle7 = 988;

const uint16_t Height1 = 1046;
const uint16_t Height2 = 1175;
const uint16_t Height3 = 1318;
const uint16_t Height4 = 1397;
const uint16_t Height5 = 1568;
const uint16_t Height6 = 1760;
const uint16_t Height7 = 1976;

const uint16_t ZERO = 0;


const uint16_t YuDieHz[] = { 
	Height1,Middle3,Middle7,Middle6,
	Middle3,Middle6,
	Height1,Middle3,Middle7,Middle6,
	Middle3,Middle6,
	Middle6,Height1,Height5,Height4,
	Height4,Height5,Height5,
	Height3,Height6,Height6,
	//
	Height6,Height6,
	Middle1,LOW3,LOW7,LOW6,//1376
	LOW6,LOW6,//66
		Middle1,LOW3,LOW7,LOW6,//1376
	LOW6,LOW6,//66
		LOW6,Middle1,Middle5,Middle4,//6154
	Middle4,Middle3,Middle4,Middle5,//4345
	//
	Middle3,Middle5,Middle6,Middle6,//3566
	//
	Middle6 ,Middle6,Middle1, LOW7,//6617
						LOW6,LOW5,LOW6,ZERO,LOW5,
						LOW6,LOW6,LOW5,LOW6,ZERO,Middle1,
							Middle2,Middle2,Middle1,Middle2,Middle1,
};
const unsigned int YuDieDuration[] = {
	500,500,500,1500,
	750,750,
	500,500,500,1500,
	750,750,
	500,500,500,1500,
	750,750,1500,
	750,750,1500,
	//
	750,750,
	500,500,500,1500,//
	1500,1500,//66
		500,500,500,1500,//
	750,750,//66
	500,500,500,1500,
	500,500,500,1500,//4345
	//
	500,500,500,1500,
	//
	1500,500,500,500,//6617
	750,750,500,500,500,
	500,500,500,500,500,500,
	500,500,500,750,750,
} ;


void playYuDie(void){
	static bool wkup_status = false;
	static int changed_count = 0;
	
	bool tmpStatus = wkup_driver_get_status();
	if(tmpStatus != wkup_status){
		wkup_status = tmpStatus;
		changed_count++;
	}
	

	if((changed_count>>1) & 0b1u){
		int index = 0;
		for(index=0;index<sizeof(YuDieHz)/sizeof(uint16_t);index++){
			//buzzer_play(YuDieHz[index],YuDieDuration[index]);
			buzzer_driver_play(YuDieHz[index],YuDieDuration[index]);
		}
	}
    
}

